"""
宏观经济数据模型
"""
from datetime import datetime
from sqlalchemy import Column, Integer, String, Float, Date, DateTime, Index
from modules.models.base import Base


class MacroEconomicData(Base):
    """宏观经济数据模型"""
    __tablename__ = "macro_economic_data"
    
    id = Column(Integer, primary_key=True, autoincrement=True)
    indicator = Column(String(100), nullable=False, index=True, comment="指标名称")
    region = Column(String(50), nullable=False, index=True, comment="地区")
    period = Column(String(20), nullable=False, comment="统计周期")
    time_point = Column(Date, nullable=False, index=True, comment="时间点")
    value = Column(Float, nullable=True, comment="数值")
    unit = Column(String(20), nullable=True, comment="单位")
    description = Column(String(500), nullable=True, comment="描述")
    create_time = Column(DateTime, default=datetime.now, comment="创建时间")
    
    __table_args__ = (
        Index('idx_macro_indicator_region', 'indicator', 'region'),
        Index('idx_macro_time_point', 'time_point'),
    )
    
    def __repr__(self):
        return f"<MacroEconomicData(indicator='{self.indicator}', region='{self.region}', time_point='{self.time_point}', value={self.value})>"


class EconomicCalendar(Base):
    """经济日历事件模型"""
    __tablename__ = "economic_calendar"
    
    id = Column(Integer, primary_key=True, autoincrement=True)
    event_date = Column(Date, nullable=False, index=True, comment="事件日期")
    event_time = Column(String(20), nullable=True, comment="事件时间")
    country = Column(String(50), nullable=False, index=True, comment="国家/地区")
    importance = Column(String(20), nullable=True, comment="重要性: 高/中/低")
    event = Column(String(500), nullable=False, comment="事件名称")
    actual = Column(String(50), nullable=True, comment="实际值")
    forecast = Column(String(50), nullable=True, comment="预测值")
    previous = Column(String(50), nullable=True, comment="前值")
    impact = Column(String(20), nullable=True, comment="影响: 利好/利空/中性")
    create_time = Column(DateTime, default=datetime.now, comment="创建时间")
    
    __table_args__ = (
        Index('idx_calendar_date_country', 'event_date', 'country'),
    )
    
    def __repr__(self):
        return f"<EconomicCalendar(date='{self.event_date}', country='{self.country}', event='{self.event[:30]}...', actual='{self.actual}')>"